package com.example.zg.zg_312_ordering_new.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;

import com.example.zg.zg_312_ordering_new.R;
import com.example.zg.zg_312_ordering_new.adapter.FoodAdapter;
import com.example.zg.zg_312_ordering_new.beans.FoodInfo;

import java.util.List;

public class SearchActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<FoodInfo> foodBeans;
    private FoodAdapter foodAdapter;
    private ImageView iv_return;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);

        iv_return=findViewById(R.id.imageView18);

        foodBeans= (List<FoodInfo>) getIntent().getSerializableExtra("foodBeans");
        initRecyclerview();
        click();
    }

    public void initRecyclerview(){
        recyclerView=findViewById(R.id.recyclerview_search_result);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        foodAdapter=new FoodAdapter();
        recyclerView.setAdapter(foodAdapter);

        foodAdapter.setData(foodBeans);
    }

    public void click(){
        foodAdapter.setOnItemClickListener(new FoodAdapter.OnItemClickListener() {
            @Override
            public void setItem(View view, int position) {
                FoodInfo foodBean=foodBeans.get(position);
                Intent intent=new Intent(SearchActivity.this,FoodInfoActivity.class);
                intent.putExtra("id",foodBean.getFood_id());
                startActivity(intent);
            }
        });

        iv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

}